<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/demo.css">
<script type="text/javascript" src="${pageContext.request.contextPath }/jq/jquery-3.2.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
<style type="text/css">
table
{
	background-color:BLUE;
}
td
{
	background-color:WHITE;
	padding:2px;
}
</style>
<script type="text/javascript">
$(function(){

//教师空格	--------------------------------------------------
	var cell="";
	//点击教师空格触发事件
	$(".teacherCell").click(function(){
		cell=this;
		$("#tw [name='course.id']").val(this.lang);
		$.post("${pageContext.request.contextPath }/course/get",{"course.id":this.lang},function(data){
			$("#courseNameFort").html(data.split("!")[1]);			
		});
		$("#tw").window("open");
	});
	
	//选择一个教师触发事件
	$(".selectteacher").click(function(){
		$("#tw [name='teacher.id']").val(this.lang);
	});
	
	//点击保存触发事件,得到教师的姓名使其设置在页面空格处，退出窗口
	$("#saveteacher").click(function(){
		$.ajaxSettings.async=false;
		//拿教师的姓名
		var teacherName="";
		$.post("${pageContext.request.contextPath }/teacher/get",
				{"teacher.id":$("#tw [name='teacher.id']").val()},
				function(data){
					teacherName=data.split("!")[1];
				});
		$.post("${pageContext.request.contextPath }/course/updateTeacher",
				{"course.id":$("#tw [name='course.id']").val(),"teacher.id":$("#tw [name='teacher.id']").val()},
				function(data){
					cell.innerHTML(teacherName);
				});
		$("#tw").window("close");
		location.href="${pageContext.request.contextPath }/course/imain";
	});




//教室空格-------------------------------------------------
	//点击教室空格触发事件
	$(".roomCell").click(function(){
		cell=this;
		$("#rw [name='course.id']").val(this.lang);
		$.post("${pageContext.request.contextPath }/course/get",{"course.id":this.lang},function(data){
			$("#courseNameForr").html(data.split("!")[1]);			
		});
		$("#rw").window("open");
	});
	
	//选择一个教室触发事件
	$(".selectroom").click(function(){
		$("#rw [name='room.id']").val(this.lang);
	});
	
	//点击保存触发事件,得到教室的名使其设置在页面空格处，退出窗口
	$("#saveroom").click(function(){
		$.ajaxSettings.async=false;
		//拿教室的姓名
		var roomName="";
		$.post("${pageContext.request.contextPath }/room/get",
				{"room.id":$("#rw [name='room.id']").val()},
				function(data){
					roomName=data.split("!")[1];
				});
		
		
 		$.post("${pageContext.request.contextPath }/course/updateroom",
				{"course.id":$("#rw [name='course.id']").val(),"room.id":$("#rw [name='room.id']").val()},
				function(data){
					cell.innerHTML(roomName);
				});
 		
		$("#rw").window("close");
		location.href="${pageContext.request.contextPath }/course/imain";
	});

});
</script>
</head>
<body>
<input type="hidden" id="page" value="${page }">

<!-- 教师-弹出窗口 -->
<div id="tw" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:500px;height:200px;padding:10px;">
	<input type="hidden" name="course.id">	
	<input type="hidden" name="teacher.id">	
<br>
您正在为课程[<span id="courseNameFort"></span>]设置教师信息..
<br>
<table>
<tr><td>选择</td><td>序号</td><td>教师名称</td><td>教师性别</td><td>电话号码</td></tr>
<s:iterator value="#TEACHERS" id="myteacher" status="st">
<tr><td><input type="radio" class="selectteacher" lang="${myteacher.id }"></td><td>${st.index+1 }</td><td>${myteacher.name }</td><td>${myteacher.sex }</td><td>${myteacher.phone }</td></tr>
</s:iterator>
</table>
<input type="button" id="saveteacher" value="保存">
</div>


<!-- 教室-弹出窗口 -->
<div id="rw" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:500px;height:200px;padding:10px;">
	<input type="hidden" name="course.id">	
	<input type="hidden" name="room.id">	
<br>
您正在为课程[<span id="courseNameForr"></span>]设置教室信息..
<br>
<table>
<tr><td>选择</td><td>序号</td><td>教室名称</td><td>教室地址</td></tr>
<s:iterator value="#ROOMS" id="myroom" status="st">
<tr><td><input type="radio" class="selectroom" lang="${myroom.id }"></td><td>${st.index+1 }</td><td>${myroom.name }</td><td>${myroom.address }</td></tr>
</s:iterator>
</table>
<input type="button" id="saveroom" value="保存">

</div>


<s:if test="#COURSES!=null">
<table>
<tr><td>序号</td><td>课程名称</td><td>课程类型</td><td>课程学时</td><td>授课教师</td><td>课室地址</td></tr>
<s:iterator value="#COURSES" id="mycourse" status="st">
<tr><td>${st.index+1 }</td><td>${mycourse.name }</td><td>${mycourse.type }</td><td>${mycourse.hours }</td>
<td class="teacherCell" lang="${mycourse.id }">${mycourse.teacher.name }</td>
<td class="roomCell" lang="${mycourse.id }">${mycourse.room.name }</td></tr>
</s:iterator>
</table>
${NAVBAR}
</s:if>
<br>
<a href="${pageContext.request.contextPath }/main.jsp">返回主页面</a>

</body>
</html>